package tictactoe;

public class TicTacToe {
    private int[][] chessboard;
    TicTacToe () {
        chessboard = new int[][] {
                {0, 0, 0},
                {0, 0, 0},
                {0, 0, 0}
        };
    }
    int place (int player, int row, int column) {
        int result;
        if (chessboard[row][column] != 0) {
            return 3;
        }
        chessboard[row][column] = player;
        for (int i = 0; i < 3; i++) {
            result = checkChessboard(chessboard[0][i], chessboard[1][i], chessboard[2][i]);
            if (result != 0) {
                return result;
            }
        }
        for (int i = 0; i < 3; i++) {
            result = checkChessboard(chessboard[i][0], chessboard[i][1], chessboard[i][2]);
            if (result != 0) {
                return result;
            }
        }
        result = checkChessboard(chessboard[0][0], chessboard[1][1], chessboard[2][2]);
        if (result != 0) {
            return result;
        }
        result = checkChessboard(chessboard[2][0], chessboard[1][1], chessboard[0][2]);
        if (result != 0) {
            return result;
        }
        return 0;
    }
    int checkChessboard (int position0, int position1, int position2) {
        if (position0 == position1 && position0 == position2) {
            return position0;
        }
        return 0;
    }
}
